<!DOCTYPE html>

<html lang="en">
<head>
    <!-- The jQuery library is a prerequisite for all jqSuite products -->
    <script type="text/ecmascript" src="../../../js/jquery.min.js"></script> 
    <!-- We support more than 40 localizations -->
    <script type="text/ecmascript" src="../../../js/trirand/i18n/grid.locale-en.js"></script>
    <!-- This is the Javascript file of jqGrid -->   
    <script type="text/ecmascript" src="../../../js/trirand/jquery.jqGrid.min.js"></script>
    <!-- A link to a Boostrap  and jqGrid Bootstrap CSS siles-->
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> 
    <link rel="stylesheet" type="text/css" media="screen" href="../../../css/trirand/ui.jqgrid-bootstrap.css" />
	<script>
		$.jgrid.defaults.width = 780;
		$.jgrid.defaults.responsive = true;
		$.jgrid.defaults.styleUI = 'Bootstrap';
	</script>
	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
    <meta charset="utf-8" />
    <title>jqGrid Loading Data - JSON</title>
</head>
<body>
<div style="margin-left:20px;">
    <table id="jqGrid"></table>
    <div id="jqGridPager"></div>
</div>    
    <script type="text/javascript"> 

        var mydata = [
               { id: "1", invdate: "2007-10-01", name: "test", note: "note", amount: "200.00", tax: "10.00", total: "210.00" },
               { id: "2", invdate: "2007-10-02", name: "test2", note: "note2", amount: "300.00", tax: "20.00", total: "320.00" },
               { id: "3", invdate: "2007-09-01", name: "test3", note: "note3", amount: "400.00", tax: "30.00", total: "430.00" },
               { id: "4", invdate: "2007-10-04", name: "test", note: "note", amount: "200.00", tax: "10.00", total: "210.00" },
               { id: "5", invdate: "2007-10-05", name: "test2", note: "note2", amount: "300.00", tax: "20.00", total: "320.00" },
               { id: "6", invdate: "2007-09-06", name: "test3", note: "note3", amount: "400.00", tax: "30.00", total: "430.00" },
               { id: "7", invdate: "2007-10-04", name: "test", note: "note", amount: "200.00", tax: "10.00", total: "210.00" },
               { id: "8", invdate: "2007-10-03", name: "test2", note: "note2", amount: "300.00", tax: "20.00", total: "320.00" },
               { id: "9", invdate: "2007-09-01", name: "test3", note: "note3", amount: "400.00", tax: "30.00", total: "430.00" }
        ];

    
        $(document).ready(function () {
            $("#jqGrid").jqGrid({
                datatype: "local",
				data: mydata,
                height: 250,
				width: 780,
                colModel: [
                    { label: 'Inv No', name: 'id', width: 75, key:true },
                    { label: 'Date', name: 'invdate', width: 90 },
                    { label: 'Client', name: 'name', width: 100 },
                    { label: 'Amount', name: 'amount', width: 80, summaryType: 'sum', formatter:'number' },
                    { label: 'Tax', name: 'tax', width: 80, summaryType: 'sum', formatter:'number' },
                    { label: 'Total', name: 'total', width: 80,
						summaryType : function(value, name, record) {
						 // initialize the value object
							if(typeof value === 'string'){
								value = {totalAmount: 0, totalTax: 0 };
							}
							// perform summary
							if(record['amount']) {
								value.totalAmount += parseFloat(record['amount']);
							}
							if(record['tax']) {
								value.totalTax += parseFloat(record['tax']);
							}
							return value;
						},
						formatter: function (cellval, opts, rwdat, act) {
							// get the regional options and pass it to the custom formatter
							opts = $.extend({}, $.jgrid.getRegional(this, 'formatter') , opts);
							// determine if we are in summary row to put the value
							if (opts.rowId === '') {
								if(cellval.totalAmount !== 0) {
									var val = (cellval.totalAmount - cellval.totalTax)/cellval.totalAmount*100;
									return $.fn.fmatter('number', val, opts, rwdat, act)+' %';
								} else {
									return '0'; 
								}
							} else {
								return $.fn.fmatter('number', cellval, opts, rwdat, act);
							}
						}
					},
                    { label: 'Notes', name: 'note', width: 150 }
                ],
                viewrecords: true, // show the current page, data rang and total records on the toolbar
                caption: "Custom Summary Type",
				grouping: true,
				groupingView: {
					groupField: ["name"],
					groupColumnShow: [true],
					groupText: ["<b>{0}</b>"],
					groupOrder: ["asc"],
					groupSummary: [true],
					groupCollapse: false
				}
            });
        });

    </script>

    <!-- This code is related to code tabs -->
    <br />
    <span style="margin-left:18px; font-family: Tahoma">Click on the Tabs below the see the relevant code for the example:</span>
    <br /><br />
    <div id="codetabs" style="height: 400px; font-size:65%;"></div>
     
    <script type="text/ecmascript" src="../../../js/prettify/prettify.js"></script>
    <link rel="stylesheet" href="../../../css/prettify.css" />
    <script type="text/ecmascript" src="../../../js/codetabs-b.js"></script> 

    
    <script type="text/javascript">

        var tabData =
            [
                { name: "HTML", url: "index.html", lang: "lang-html" },
				{ name: "Description", url: "description.html", lang: "lang-html" }
            ];

        codeTabs(tabData);

    </script>
    <!-- End of code related to code tabs -->
</body>
</html>